from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone

class UserProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile', verbose_name='用户')
    avatar = models.ImageField(upload_to='avatars/', null=True, blank=True, verbose_name='头像')
    bio = models.TextField(max_length=500, blank=True, verbose_name='个人简介')
    social_media = models.JSONField(default=dict, blank=True, verbose_name='社交媒体链接')
    is_creator = models.BooleanField(default=False, verbose_name='创作者身份')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='创建时间')
    # 用户封禁相关字段
    is_banned = models.BooleanField(default=False, verbose_name='是否封禁')
    ban_reason = models.TextField(blank=True, verbose_name='封禁原因')
    ban_time = models.DateTimeField(null=True, blank=True, verbose_name='封禁时间')
    
    class Meta:
        verbose_name = '用户资料'
        verbose_name_plural = '用户资料'
    
    def __str__(self):
        return f'{self.user.username}的资料'

class UserActivity(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='activities', verbose_name='用户')
    activity_type = models.CharField(max_length=50, verbose_name='活动类型')
    activity_data = models.JSONField(default=dict, verbose_name='活动数据')
    created_at = models.DateTimeField(default=timezone.now, verbose_name='活动时间')
    
    class Meta:
        verbose_name = '用户活动'
        verbose_name_plural = '用户活动'
        ordering = ['-created_at']
    
    def __str__(self):
        return f'{self.user.username}的{self.activity_type}活动'
